
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<script type="text/javascript">

    function cleargateForm(){
        $('#gateForm').form('clear');
    }

    function displayErrorTab() {
        if ($('#gateForm').form('validate')) {
            return true;
        } else {
            var invalid=$('.validatebox-invalid','#gateForm').first();
            var parentTable=invalid.parents('table');
            var table=parentTable[0];
            var id=$(table).attr('id');
            //alert("id="+id);
            var index=Number(id.substring(id.length-1));
            $('#tabs_gate').tabs('select',index);
            $('#gateForm').form('validate');
            return false;
        }
    }

    function addRivergate() {
        cleargateForm();
        $('#obj_id').val('');
        $("#oprt").val("add");
        map = new AMap.Map('map', {
            resizeEnable: true,
            zoom:12,
            center: [102.710212,25.0548]
        });
        map.plugin(["AMap.ToolBar"], function() {
            map.addControl(new AMap.ToolBar());
        });
    }

    function editRivergate(id) {
        cleargateForm();
        $("#oprt").val("update");
        $.ajax({url:"__URL__/get_gate_json",data:{'id':id},dataType:"json",success:function(json, textStatus){
            console.log(json);
            jQuery('#gateForm').form('load',{
                "id": json.id,
                "gate_number": json.gate_number,
                "status": json.status,
                'mobile':json.mobile,
                'phone':json.phone,
                "gate_point": json.gate_point,
                'gate_opr':json.gate_opr,
                'gate_name':json.gate_name,
                'gate_type':json.gate_type,
                'gate_mrf':json.gate_mrf,
                'gate_model':json.gate_model,
                'gate_motorpower':json.gate_motorpower,
                'gate_blev':json.gate_blev,
                'gate_h':json.gate_h,
                'gate_wid':json.gate_wid,
                'gate_ctltype':json.gate_ctltype,
                'gate_switsty':json.gate_switsty,
                'gate_rownum':json.gate_rownum,
                'gate_holenum':json.gate_holenum,
                'gate_svcdt':json.gate_svcdt,
                'note':json.note,
                'gate_address':json.gate_address,
                'opr_temp':json.gate_opr_names

            });
            //标记当前泵机
            $('#rivergate_id').val(json.id);
            console.log($('#rivergate_id').val());
            //在地图上标出来
            var gps = json.gate_point;
            if(gps != ''){
                gps = gps.split(",");
                gps = [gps[0],gps[1]];
//                gps = [102.710212,25.0548];
                $('#long').val(gps[0]);
                $('#lat').val(gps[1]);
            }else{
                gps = [102.710212,25.0548];
            }
            map = new AMap.Map('map', {
                resizeEnable: true,
                zoom:12,
                center: gps
            });
            map.plugin(["AMap.ToolBar"], function() {
                map.addControl(new AMap.ToolBar());
            });
            marker = new AMap.Marker({
                position: gps
            });
            marker.setMap(map);
            markers.push(marker);
            $('#stopListen').linkbutton('disable');
            $('#getPoint').linkbutton('enable');
//            setFormFocus('#gateForm');
        },error:function(XMLHttpRequest, textStatus, errorThrown)
        {
            relogin(XMLHttpRequest, textStatus, errorThrown);
        }});
    }

    function formatFileName(name){
        var fname = name.substring(7,name.lastIndexOf("."));
        var fExtName = name.substring(name.lastIndexOf(".")+1);
        var len = fname.length-24;
        fname = fname.substring(0,len+1)+"."+fExtName;
        return fname;
    }

    function submitgateForm() {
        if (displayErrorTab()) {
            var submitflag = jQuery("#oprt").val();
            console.log(submitflag);
            var url = "";
            if (submitflag === "add")
                url = "__URL__/add";
            if (submitflag === "update")
                url = "__URL__/edit";
            $('#gateForm').ajaxSubmit({
                url:url,
                dataType:'json',
                async: false,
                success: function(data) {
                    if (data.status=="1") {
                        $('#listDialog').dialog('close');
                        $.messager.show({title:'提示',msg:'保存河道闸门基础信息成功！',showType:'slide'});
                    }
                    else $.messager.alert('提示','操作失败！原因:'+data.msg,'error');
                }
            });
        }
    }

    //高德地图插件
    var map = new AMap.Map('map', {
        resizeEnable: true,
        zoom:12,
        center: [102.710212,25.0548]
    });
    map.plugin(["AMap.ToolBar"], function() {
        map.addControl(new AMap.ToolBar());
    });
    //地图获取gps坐标回调函数
    var markers = [];
    var callBackFn = function(e) {
        map.remove(markers);
        var marker = new AMap.Marker({
            map: map,
            position: [e.lnglat.getLng(), e.lnglat.getLat()]
        });
        markers.push(marker);
        $('#long').val(e.lnglat.getLng());
        $('#lat').val(e.lnglat.getLat());
        $('#gps').val(e.lnglat.getLng()+','+e.lnglat.getLat());
    };
    function getPoint(){
        $('#getPoint').linkbutton('disable');
        $('#stopListen').linkbutton('enable');
        map.on('click', callBackFn);
    }
    function stopPoiont(){
        $('#getPoint').linkbutton('enable');
        map.off('click', callBackFn);
    }
    function getLocation(){
        if($('#gate_address').val()==null||$.trim($('#gate_address').val())==''){
            $.messager.alert('提示','请填写地址后再定位！','error');
            return;
        }
        AMap.service(["AMap.PlaceSearch"], function() {
            var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                pageSize: 5,
                pageIndex: 1,
                city: "010", //城市
                map: map,
                panel: "panel"
            });
            //关键字查询
            var keyword = $('#gate_address').val();
            placeSearch.search(keyword);
        });
    }
    <?php if(I('get.justsee')){?>
    $('#gateForm input').attr('readonly', true);
    $('#gateForm select').attr('readonly', true);
    $('#gateForm textarea').attr('readonly', true);
    $('#gateForm #opr').attr('onclick', '');
    $('#getPoint,#stopListen').hide();
    <?php }?>
</script>
<form id="gateForm" method="post" enctype="multipart/form-data" action="">
    <input type="hidden" id="oprt" name="oprt" value="add">
    <input type="hidden" name="id" id="obj_id" />
    <div id="tabs_gate" class="easyui-tabs"  plain="true"  style="height:400px;width:800px;" <?php if(!I('get.justsee')){?>tools="#tab-tools-pumpstation"<?php }?>>
        <div title="基本信息" style="padding:10px;">
            <table border="0" id='table0'>
                <tr>
                    <td>闸门名称：</td>
                    <td>
                        <input id="csdt_name" class="easyui-validatebox" type="text" name="gate_name" style="width:400px" required="true"></input>
                    </td>
                </tr>

                <tr>
                    <td>闸门编号：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="gate_number" style="width:400px"></input>
                    </td>
                </tr>
                <tr>
                    <td>闸门控制类型：</td>
                    <td>
                        <select class="easyui-combobox" name="gate_ctltype" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 100px;">
                            {:gate_cont_type_option()}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>闸门启闭型式：</td>
                    <td>
                        <select class="easyui-combobox" name="gate_switsty" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 100px;">
                            {:gate_swit_sty_option()}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>执勤电话：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="mobile" style="width:200px"></input>
                    </td>
                </tr>
                <tr>
                    <td>座机：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="phone" style="width:200px"></input>
                    </td>
                </tr>
                <tr>
                    <td>投运日期：</td>
                    <td>
                        <input type="text" id="" class=" easyui-datebox" name="gate_svcdt" style="width:140px">
                    </td>
                </tr>

                <tr>
                    <td>闸门厂家：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="gate_mrf" style="width:400px"></input>
                    </td>

                </tr>
                <tr>
                    <td>闸门型号：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="gate_model" style="width:400px"></input>
                    </td>
                </tr>
                <tr>
                    <td>{:LANG('opr')}: </td>
                    <td>
                        <textarea id="opr" name="opr_temp" style="width: 300px;height: 100px;" readonly="true" onclick="open_dialog('/Manage/AdminMobileAdmin//show_mobile_admin?ids='+$('#opr_ids').val())"></textarea>
                        <input type="hidden" id="opr_ids" name="gate_opr">
                    </td>
                </tr>
                <tr>
                    <td>河道闸门简介：</td>
                    <td>
                        <textarea name="note" style="width:400px;height:60px"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>高程：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="gate_blev" precision="4" style="width:150px;"></input>
                    </td>
                </tr>
                <tr>
                    <td>闸门宽：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="gate_wid" precision="4" style="width:150px;"></input>
                    </td>
                </tr>
                <tr>
                    <td>闸门高：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="gate_h" precision="4" style="width:150px;"></input>
                    </td>
                </tr>
                <tr>
                    <td>闸门排数：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="gate_rownum" style="width:150px;"></input>
                    </td>
                </tr>
                <tr>
                    <td>闸门孔数：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="gate_holenum" style="width:150px;"></input>
                    </td>
                </tr>

            </table>
        </div>
        <div title="位置信息" fit=true style="padding:10px;">
            <table border="0" id='table1'>
                <tr>
                    <td>河道闸门地址：</td>
                    <td colspan=3>
                        <input class="easyui-validatebox" required=true id='gate_address' type="text" name="gate_address" style="width:300px"></input>
                        <input id='gps' type="hidden" name="gate_point"  style="width:120px" readonly="true" required=true></input>
<!--                        <span><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick='getLocation()'>地图定位</a></span>-->
                    </td>
                </tr>

                <tr>
                    <td>经度：</td>
                    <td>
                        <input class="easyui-validatebox" id='long' type="text"   style="width:120px" readonly required=true></input>
                    </td>
                    <td>纬度：</td>
                    <td>
                        <input class="easyui-validatebox" id='lat' type="text"  style="width:120px" readonly required=true></input>
                        <span><a id='getPoint' href="#" class="easyui-linkbutton" data-options="iconCls:'icon_ext icon-gps'" onclick='getPoint()'>点选经纬度</a></span>
                        <span><a id='stopListen' href="#" class="easyui-linkbutton"  data-options="iconCls:'icon-ok'" onclick="stopPoiont()">确定</a></span>
                    </td>
                </tr>
            </table>
            <div id="map" class="easyui-panel" data-options="fit:true,border:false">
            </div>
        </div>

<!--        <div title="设计及运行参数" style="padding:10px;">-->
<!--            <table border="0" id='table2'>-->
<!--                <tr>-->
<!--                    <td>电机功率：</td>-->
<!--                    <td colspan=3>-->
<!--                        <input class="easyui-numberbox" type="text" name="gate_motorpower" style="width:100px" min=0></input>(KW)-->
<!--                    </td>-->
<!--                </tr>-->
<!--                <tr>-->
<!--                    <td>闸门高程：</td>-->
<!--                    <td colspan=3>-->
<!--                        <input class="easyui-numberbox" type="text" name="gate_blev" style="width:120px"></input>(m)-->
<!--                    </td>-->
<!--                </tr>-->
<!--                <tr>-->
<!--                    <td>闸门净高：</td>-->
<!--                    <td>-->
<!--                        <input class="easyui-numberbox" type="text" name="gate_h" style="width:120px" min=0></input>(m)-->
<!--                    </td>-->
<!--                </tr>-->
<!--                <tr>-->
<!--                    <td>闸门净宽：</td>-->
<!--                    <td>-->
<!--                        <input class="easyui-numberbox" type="text" name="gate_wid" style="width:120px" min=0></input>(m)-->
<!--                    </td>-->
<!--                </tr>-->
<!--                <tr>-->
<!--                    <td>闸门排数：</td>-->
<!--                    <td>-->
<!--                        <input class="easyui-numberbox" type="text" name="gate_rownum" style="width:120px" min=0></input>-->
<!--                    </td>-->
<!---->
<!--                </tr>-->
<!--                <tr>-->
<!--                    <td>闸门孔数：</td>-->
<!--                    <td>-->
<!--                        <input class="easyui-numberbox" type="text" name="gate_holenum" style="width:120px" min=0></input>-->
<!--                    </td>-->
<!--                </tr>-->
<!--            </table>-->
<!--        </div>-->
<!---->
<!---->
<!--        <div title="河道闸门实景图" style="padding:10px;">-->
<!---->
<!--        </div>-->

    </div>
    <?php if(!I('get.justsee')){?>
    <div id="tab-tools-pumpstation">
        <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:submitgateForm();">保存河道闸门基本信息</a>
    </div>
    <?php }?>
</form>